FROM node:20-alpine

# 设置 npm 淘宝镜像
RUN npm config set registry https://registry.npmmirror.com

# 安装系统依赖
RUN apk add \
    graphicsmagick \
    build-base

# 设置 Node.js 内存限制
ENV NODE_OPTIONS="--max-old-space-size=4096"

WORKDIR /app

# 复制 package.json 和 package-lock.json
COPY backend/package*.json ./

# 安装依赖
RUN npm install --production

# 复制后端源代码
COPY backend/ .

# 创建上传目录
RUN mkdir -p uploads && chmod 777 uploads

# 创建前端构建目录
RUN mkdir -p build

# 暴露端口
EXPOSE 5000

# 启动命令
CMD ["npm", "start"] 